package com.ruoyi.project.stat.paeaReportWorkload.domain;

import java.sql.Date;
import java.text.ParseException;
import java.text.SimpleDateFormat;

public class StatisticsDateWrapper {
	private Date dateDay = null;
	private Date endDate = null;
	private Date beginMonthDay = null;
	private Date beginNextMonthDay = null;
	private Date beginYearDay = null;
	private Date endYearDay = null;
	private final static SimpleDateFormat f = new SimpleDateFormat("yyyyMMdd");

	public Date getDateDay() {
		return dateDay;
	}
	public String parseDate(Date date) {
		return f.format(date);
	}
	public void setDateDay(Date dateDay) {
		this.dateDay = dateDay;
	}

	public Date getBeginMonthDay() {
		return beginMonthDay;
	}

	public void setBeginMonthDay(Date beginMonthDay) {
		this.beginMonthDay = beginMonthDay;
	}

	public Date getBeginNextMonthDay() {
		return beginNextMonthDay;
	}

	public void setBeginNextMonthDay(Date beginNextMonthDay) {
		this.beginNextMonthDay = beginNextMonthDay;
	}

	public Date getBeginYearDay() {
		return beginYearDay;
	}

	public void setBeginYearDay(Date beginYearDay) {
		this.beginYearDay = beginYearDay;
	}

	public Date getEndYearDay() {
		return endYearDay;
	}

	public void setEndYearDay(Date endYearDay) {
		this.endYearDay = endYearDay;
	}
	public static StatisticsDateWrapper getStatisticsDateWrapper(Date date) {
		return getStatisticsDateWrapper(f.format(date), null); 
	}
	public static StatisticsDateWrapper getStatisticsDateWrapper(String date, String endDate) {
		if (date == null)
			return null;
		if (date != null && date.length() == 10) {
			date = date.substring(0, 4) + date.substring(5, 7)
					+ date.substring(8, 10);
		}
		if (endDate != null && endDate.length() == 10) {
			endDate = endDate.substring(0, 4) + endDate.substring(5, 7)
					+ endDate.substring(8, 10);
		}
		if(null == endDate || endDate.length()==0){
			if(date.length() == 10){
				endDate = date.substring(0, 4) + date.substring(5, 7)
						+ date.substring(8, 10);
			}else{
				endDate = date;
			}
		}
		int year = Integer.valueOf(date.substring(0, 4)).intValue();
		int month = Integer.valueOf(date.substring(4, 6)).intValue();
		int nextYear = year + 1;
		int nextMonth = month == 12 ? 1 : (month + 1);
		String beginMonth = date.substring(0, 6) + "01";
		String beginNextMonth = (month == 12 ? nextYear : year) + ""
				+ (nextMonth > 9 ? (nextMonth + "") : ("0" + nextMonth)) + "01";
		String beginYear = year + "0101";
		String endYear = year + "1231";
		StatisticsDateWrapper statisticsDateWrapper = new StatisticsDateWrapper();
		try {
			statisticsDateWrapper.dateDay = new Date(f.parse(date).getTime());
			statisticsDateWrapper.endDate =endDate==null?null: new Date(f.parse(endDate).getTime());
			statisticsDateWrapper.beginMonthDay = new Date(f.parse(beginMonth)
					.getTime());
			statisticsDateWrapper.beginNextMonthDay = new Date(f.parse(
					beginNextMonth).getTime());
			statisticsDateWrapper.beginYearDay = new Date(f.parse(beginYear)
					.getTime());
			statisticsDateWrapper.endYearDay = new Date(f.parse(endYear)
					.getTime());

		} catch (ParseException ex) {
		}
		return statisticsDateWrapper;
	}

	public Date getEndDate() {
		return endDate;
	}

	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}
}
